-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XML: Add a contextual version of the parser for XML #2935
Conversation
Hi @jcazevedo, Thank you for your contribution! We really value the time you've taken to put this together. Before we proceed with reviewing this pull request, please sign the Lightbend Contributors License Agreement: |
532deb2
to
e58ce3b
Compare
val in: Inlet[ByteString] = Inlet("XMLParser.in") | ||
val out: Outlet[ParseEvent] = Outlet("XMLParser.out") | ||
override val shape: FlowShape[ByteString, ParseEvent] = FlowShape(in, out) | ||
@InternalApi private[xml] class StreamingXmlParser[Ctx](ignoreInvalidChars: Boolean, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should keep the non-context version around separately to not burden it with unneeded tuple creation. But maybe that would become too much duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose we can avoid some duplication by letting callers of the internal API decide how elements in the flow are created, at the expense of complicating the internal API (d66f71c). What do you think?
Attempts to avoid the unnecessary creation of tuples by parameterizing the internal API and letting callers decide how elements in the flow are built.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's better.
getByteString = identity, | ||
getContext = _ => (), | ||
buildOutput = (parseEvent, _) => parseEvent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about putting the three fixed transform methods into a class with two objects as implementations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. I did that in 2d980fb.
configureFactory, | ||
getByteString = _._1, | ||
getContext = _._2, | ||
buildOutput = (pe, ctx) => (pe, ctx)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
buildOutput = (pe, ctx) => (pe, ctx)) | |
buildOutput = identity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Close now.
A few more suggestions.
xml/src/main/scala/akka/stream/alpakka/xml/javadsl/XmlParsing.scala
Outdated
Show resolved
Hide resolved
xml/src/main/scala/akka/stream/alpakka/xml/javadsl/XmlParsing.scala
Outdated
Show resolved
Hide resolved
xml/src/main/scala/akka/stream/alpakka/xml/javadsl/XmlParsing.scala
Outdated
Show resolved
Hide resolved
xml/src/main/scala/akka/stream/alpakka/xml/scaladsl/XmlParsing.scala
Outdated
Show resolved
Hide resolved
xml/src/main/scala/akka/stream/alpakka/xml/javadsl/XmlParsing.scala
Outdated
Show resolved
Hide resolved
xml/src/main/scala/akka/stream/alpakka/xml/impl/StreamingXmlParser.scala
Outdated
Show resolved
Hide resolved
@ennru: Thank you for your review! I have applied all of your suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
This pull request adds a contextual version of the parser provided by
XmlParsing
.API-wise, I was not entirely sure how to set this up, since different modules seem to follow different conventions. For example, the Cassandra module provides a
withContext
method directly in theCassandraFlow
object (https://github.com/akka/alpakka/blob/4f77c8b6b7e443acb39fa3164613c19a626e530f/cassandra/src/main/scala/akka/stream/alpakka/cassandra/scaladsl/CassandraFlow.scala), but the AMQP module provides its ownAmqpFlowWithContext
object with contextual variants (https://github.com/akka/alpakka/blob/4f77c8b6b7e443acb39fa3164613c19a626e530f/amqp/src/main/scala/akka/stream/alpakka/amqp/scaladsl/AmqpFlowWithContext.scala).